<template>
    <div>
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <!-- 通过 pattern 进行正则校验 -->
                <van-field v-model="password" type="password" name="password" label="密码" placeholder="密码" :rules="[
                    { required: true, message: '请填写密码' },
                    { pattern, message: '请填写正确的2-11位密码' }]" />
            </van-cell-group>

            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    登录
                </van-button>
            </div>
        </van-form>
    </div>
</template>
 
<script setup lang="ts">
import { ref } from 'vue';

import { getFinishRegister } from '@/api/user'

import { useUserStore } from '@/store/useStore'

import { useRouter } from 'vue-router';
const user = useUserStore();

const router  = useRouter();

const pattern = /^\d{2,11}$/
const password = ref('')

const onSubmit = async () => {
    // 需要两个数据： 电话和密码  
    // 1. 获取电话 =》 从 pinia里面
    // 2. 密码  password.value
    // 3.  发送请求  注册成功就 跳转到登录页面 进行登录

console.log(111111111111);

    // 注册
    let res = await getFinishRegister({ tel: user.tel,password:password.value });

    console.log(res,666666);
    
    if(res.code == '200'){
        router.push('/login')
    }
}



</script>
 
<style scoped lang="scss">
:deep(.van-cell-group--inset) {
    margin-top: 10px;
}
</style>